#include <57header.h>

pthread_mutex_t lock;

void *func(void *p){

    sleep(1);

    while(1){
        int res = pthread_mutex_trylock(&lock);
        if(res != 0){
            printf("没有拿到锁 \n");
            continue;
        }
        printf("拿到了锁 \n");
        pthread_mutex_unlock(&lock);
    }

    return NULL;
}
int main(int argc,char*argv[])
{
    pthread_mutex_init(&lock, NULL);

    pthread_t son_id;
    pthread_create(&son_id, NULL, func, NULL);

    pthread_mutex_lock(&lock);
    sleep(200);
    pthread_mutex_unlock(&lock);

    pthread_join(son_id, NULL);
    return 0;
}

